package com.woniuxy.joylifemarket.service.impl;

import com.woniuxy.common.entity.CenterUser;
import com.woniuxy.common.entity.MarketLeavemessage;
import com.woniuxy.common.mapper.CenterUserMapper;
import com.woniuxy.common.mapper.MarketLeavemessageMapper;
import com.woniuxy.common.utils.KeyUtil;
import com.woniuxy.joylifemarket.service.MarketLeaveMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MarketLeaveMessageServiceImpl implements MarketLeaveMessageService {
    @Autowired
    MarketLeavemessageMapper marketLeavemessageMapper;
    @Autowired
    CenterUserMapper centerUserMapper;

    @Override
    public List<MarketLeavemessage> findAllLeaveMessageByCommodityId(String commodityid) {
        List<MarketLeavemessage> marketLeavemessages = marketLeavemessageMapper.selectAllLeaveMessageByCommodityId(commodityid);
        for (MarketLeavemessage marketLeavemessage: marketLeavemessages) {
            CenterUser centerUser = centerUserMapper.selectByPrimaryKey(marketLeavemessage.getUserId());
            marketLeavemessage.setUser(centerUser);
        }
        return marketLeavemessages;
    }

    @Override
    public int insertLeaveMessage(MarketLeavemessage marketLeavemessage) {
        marketLeavemessage.setId(KeyUtil.generateKey());
        marketLeavemessage.setDate(new Date());
        int i = marketLeavemessageMapper.insertSelective(marketLeavemessage);
        return i;
    }
}
